import java.lang.System;

/**
 * 反转字符串
 *
 * 示例 1：
 * 输⼊：["h","e","l","l","o"]
 * 输出：["o","l","l","e","h"]
 */
public class ReverseString {

    // 递归解法会占用递归栈空间
    public String solution(String s) {
        int len = s.length();
        if (len <= 1) {
            return s;
        }
        String leftStr = s.substring(0, len / 2);
        String rightStr = s.substring(len / 2, len);
        return solution(rightStr) + solution(leftStr);
    }

    // 双指针解法
    public void solution2(char[] nums) {
        int len = nums.length;
        for (int l = 0, r = len -1; l < r; ++l, --r){
            char t = nums[l];
            nums[l] = nums[r];
            nums[r] = t;
        }
    }

    public static void main(String[] args) {
        String s = "hello";
        System.out.println(new ReverseString().solution(s));
    }
}